package cc.abanlee.framework.common.validation.validator;

import cc.abanlee.framework.common.util.validation.ValidationUtils;
import cc.abanlee.framework.common.validation.Mobile;
import cn.hutool.core.util.StrUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 手机号码校验
 * @author: create by
 * @version: v1.0
 * @description:
 * @date:2022/8/17
 */
public class MobileValidator implements ConstraintValidator<Mobile,String> {
    @Override
    public void initialize(Mobile constraintAnnotation) {

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {

        if(StrUtil.isEmpty(value)){
            return true;
        }
        return ValidationUtils.isMobile(value);
    }
}
